package org.front.client.widget;

import org.front.client.widget.mainwidget.event.MainWidgetEvent;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.MenuBar;

public class NavigationWidget extends Composite {

	private FlowPanel rootPanel;

	EventBus eventBus;

	public NavigationWidget(EventBus eventBus) {

		this.eventBus = eventBus;
		rootPanel = new FlowPanel();
		rootPanel.add(getMenu());
		initWidget(rootPanel);
	}

	private MenuBar getMenu() {

		Command afficherDistributeur = new Command() {
			public void execute() {
				MainWidgetEvent event = new MainWidgetEvent();
				event.getContext().setAction(MainWidgetEvent.Context.Action.AFFICHER_DISTRIBUTEUR);
				eventBus.fireEvent(event);
			}
		};

		Command afficherTransaction = new Command() {
			public void execute() {
				MainWidgetEvent event = new MainWidgetEvent();
				event.getContext().setAction(MainWidgetEvent.Context.Action.AFFICHER_TRANSACTION);
				eventBus.fireEvent(event);
			}
		};

		Command afficherMeilleursProduit = new Command() {
			public void execute() {
				MainWidgetEvent event = new MainWidgetEvent();
				event.getContext().setAction(MainWidgetEvent.Context.Action.AFFICHER_MEILLEUR_PRODUIT);
				eventBus.fireEvent(event);
			}
		};

		Command afficherBenefice = new Command() {
			public void execute() {
				MainWidgetEvent event = new MainWidgetEvent();
				event.getContext().setAction(MainWidgetEvent.Context.Action.AFFICHER_BENEFICE_MOIS);
				eventBus.fireEvent(event);
			}
		};

		// Make a new menu bar, adding a few cascading menus to it.
		MenuBar menu = new MenuBar();
		menu.setAnimationEnabled(true);
		menu.addItem("Distributeur", afficherDistributeur);
		menu.addItem("Transactions", afficherTransaction);
		menu.addItem("Meilleurs Produits", afficherMeilleursProduit);
		menu.addItem("Benefice", afficherBenefice);
		return menu;
	}
}
